package com.holly.unit.bpmn.modular.activiti.controller;

import com.holly.unit.bpmn.activiti.ActivitiOperator;
import com.holly.unit.bpmn.activiti.entity.ActivitiZNodeAuth;
import com.holly.unit.bpmn.activiti.pojo.ActivitiZNodeAuthRequest;
import com.holly.unit.core.pojo.response.ResponseData;
import com.holly.unit.core.pojo.response.SuccessResponseData;
import com.holly.unit.scanner.api.annotation.ApiResource;
import com.holly.unit.scanner.api.annotation.GetResource;
import com.holly.unit.scanner.api.annotation.PostResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类描述: 工作流表单字段权限控制器
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/4/20 8:34
 */
@RestController
@ApiResource(name = "工作流表单字段权限相关API")
@Api(tags = "工作流表单字段权限API")
@Slf4j
public class ActFormColAuthController {

    @Resource
    private ActivitiOperator operator;

    @ApiOperation("新增工作流节点表单字段权限")
    @PostResource(name = "新增工作流节点表单字段权限", path = "/processNodeAuth/add")
    public ResponseData add(@RequestBody @Validated(ActivitiZNodeAuthRequest.add.class) ActivitiZNodeAuthRequest request){
        operator.saveActZNodeAuth(request);
        return new SuccessResponseData();
    }

    @ApiOperation("根据表单的编码和流程定义id和流程任务id查询表单中都有哪些授权字段")
    @GetResource(name = "根据表单的编码和流程定义id和流程任务id查询表单中都有哪些授权字段", path = "/processNodeAuth/fetchActFormColByTaskId")
    public ResponseData fetchActFormColByTaskId(@Validated(ActivitiZNodeAuthRequest.checkProcessIdAndTaskIdIsNull.class) ActivitiZNodeAuthRequest request){
        List<ActivitiZNodeAuth> ans = operator.fetchActFormColByTaskId(request.getProcessId(), request.getTaskId(),request.getFormBizCode());
        return new SuccessResponseData(ans);
    }

    @ApiOperation("编辑工作流节点表单字段权限")
    @PostResource(name = "编辑工作流节点表单字段权限", path = "/processNodeAuth/modify")
    public ResponseData update(@RequestBody @Validated(ActivitiZNodeAuthRequest.edit.class) ActivitiZNodeAuthRequest request){
        operator.saveActZNodeAuth(request);
        return new SuccessResponseData();
    }
}
